package com.company.book_store.web.servlet;

import com.alibaba.fastjson.JSON;
import com.company.book_store.service.Iuserservice;
import com.company.book_store.service.UserserviceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

@WebServlet("/borrow")
public class bookBorrow extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Iuserservice iuserservice = new UserserviceImpl();
        int book_id =  Integer.parseInt(req.getParameter("book_id")) ;
        String account = req.getParameter("account");
        Map<String,Integer>map = new HashMap<>();
       int i =  iuserservice.borrow(account,book_id);
        if(i==1){
           map.put("massage",1);
        }
        else map.put("massage",0);
        String str = JSON.toJSONString(map);
        PrintWriter out = resp.getWriter();
        out.write(str);
    }
}
